var pageParam={};
function returnHome(){
    $$.goUrl("/iot/task/task_data_list.html?taskId="+pageParam.taskId+'&taskCode='+pageParam.taskCode);
}

function updateLoad(){
    pageParam =$$.getQueryString();
    $$.ajax({
        url:"/rest/IotTaskDataBusiness/query",
        data : {
            id : pageParam.rowId
        },
        success : function(data){
            $("#b_id").val(data.id);
            $("#b_taskId").val(data.taskId);

            $("#b_taskCode").val(data.taskCode);

            $("#b_iotTable").val(data.iotTable);

            $("#b_iotCode").val(data.iotCode);

            $("#b_iotTm").val(data.iotTm);

            $("#b_iotName").val(data.iotName);

            $("#b_iotExpr").val(data.iotExpr);

            $("#b_iotDexpr").val(data.iotDexpr);

            $("#b_iotScale").val(data.iotScale);

            $("#b_uuid").val(data.uuid);

            $("#b_status").val(data.status);

            $("#b_rowSort").val(data.rowSort);

            $("#b_remarks").val(data.remarks);

            var status=data.status;

            $("input[name^='b_status_']").each(function(){

                if($(this).val()==status){

                    this.checked='checked';

                }

            });


            $("#b_task_dataCodeOld").val(data.task_dataCode);



        }
    });



}

function addInit(){
    pageParam =$$.getQueryString();
    console.log("##pageParam:"+JSON.stringify(pageParam));

    $("#b_taskId").val(pageParam.taskId);
    $("#b_taskCode").val(pageParam.taskCode);
    $("#b_uuid").val(Math.uuid());


}


$(function(){

    $('#taskCode').focus();
    dataFormValid();
    //保存验证
    $("#subBtn").on('click',function () {
        addData();
       // submitForm();
    });
    $("#btn_ret").on('click',function () {
        returnHome();
    })
})
function addData() {
    var param = {};
    $$.form({
        checkForm: validForm,
        success: function () {
            $$.alert("成功！");
            returnHome();
        }
    });

}
function validForm(){
    var ret=$('#theform').valid();
    console.log("==validForm:=="+ret);
    return ret;
}

function dataFormValid() {
    $("#theform").validate({
        rules: {
            b_taskCode: {
                required: true,
                minlength: 3,
                number: true,
                //isCode:true
            },
            b_taskName: {
                required: true,
                minlength: 3,
            },
            b_iotTable:{
                required: true,
                minlength: 6,
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errorDevice",
        success: 'valid',
        messages: {
            b_taskCode: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
                number: "请输入数字",
            },
            b_taskName: {
                required: " (必填)",
                minlength: " (不能少于 3 个字母)",
            },
            b_iotTable:{
                required: " (必填)",
                minlength: " (不能3 个字母)"
            }
        },
    });
}

function submitForm() {
    if($('#taskDataForm').valid()){
        return false;
    }
    return {};
}
